<?php
require_once(realpath(DOCUMENT_ROOT) . PROJECT_BASE . TILEPATH . 'TileFactory.php');
require_once(realpath(DOCUMENT_ROOT) . PROJECT_BASE . ENUMPATH . 'TileEnum.php');
require_once(realpath(DOCUMENT_ROOT) . PROJECT_BASE . UTILPATH . 'Util.php');

class Map {
    private $tileSet = array();
    private $tileRow = array();
    private $height;
    private $width;

    public function __construct($height, $width) {
        $this->height = $height;
        $this->width  = $width;
        $this->generateMap();
    }

    private function generateMap() {
        for($i = 0; $i < $this->height; $i++) {
            for($j = 0; $j < $this->width; $j++) {

                // Rand bestimmen
                if( ($i == 0 && $j <= ($this->width-1)) ||
                    ($j == 0 && $i > 0) ||
                    ($j > 0 && $i == ($this->height-1)) ||
                    ($i > 0 && $j == ($this->width-1))
                  ) {
                    $end = 3;
                } else {
                    $end = 1;
                }
                $tileEnum = new TileEnum(Util::generateRandomNumber(1, $end));
                $this->tileRow[$j] = TileFactory::factory($tileEnum->code());
            }
            $this->tileSet[$i] = $this->tileRow;
        }
    }

    public function getTileSet() {
        return $this->tileSet;
    }
}